package com.af.system.servlet.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;

/**
 * @author : zhenyun.su
 * @comment : 在应用程序启动就绪之后才被触发, spring 提供很多关于容器生命周期时事件
 * 其他事件：
 *    ApplicationStartedEvent, ApplicationStartingEvent, ApplicationFailedEvent, ApplicationPreparedEvent
 * 功能说明:
 * 1. 可用于在容器启动成功后，初始化数据
 * 2. 另外 spring 提供很多关于容器生命周期时事件
 * 使用说明:
 * 1. 通过配置类实例化SzyApplicationReadyListener
 * 2. 实现SystemInitialize接口类并注入到SzyApplicationReadyListener
 * 总结: 可将本类和SystemInitialize 放入common模块中 * @since : 2020/3/25
 */

public class AfApplicationReadyListener implements ApplicationListener<ApplicationReadyEvent> {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private SystemInitialize systemInitialize;

    public AfApplicationReadyListener(SystemInitialize systemInitialize) {
        this.systemInitialize = systemInitialize;
    }

    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
        logger.info("af, trigger applicationReadyEvent");

        systemInitialize.initialize();
    }
}
